/**
 * Facade around fierry.dao to enable easy configuration handling.
 * @param Any ctx
 * @param Boolean noTracking - builds storage without observable to disable trace.
 */
Core.Runtime.Args = function(ctx, noTracking) {
	this.observable = new Core.Storage.Observable();
	
	this.storage = new Core.Storage.Configuration(noTracking ? null : this.observable);
	this.valuer = new Core.Storage.DaoProxy(ctx, this.storage, this.observable);
};

Core.Runtime.Args.prototype = {
	
	/**
	 * Returns the value from underlying storage.
	 * Evaluates the value if function forced to evaluate.
	 * 
	 * @param String path
	 * @param Core.Storage.Trace trace - tracing object or null.
	 * @param Boolean fe - force to evaluate type:"function" if set to true. 
	 */
	get: function(raw, trace, fe) {
		return this.valuer.get(raw, trace, fe);
	},
	
	/**
	 * Returns all existing configuration's properties names.
	 */
	keys: function() {
		return this.storage.keys();
	},
	
	/**
	 * Sets the value into global storage.
	 * Accepts multilevel dao expression only if it points to the global storage.
	 * Will throw an error if the path points to the configuration storage primitive.
	 * 
	 * @param String path
	 * @param Any value
	 */
	set: function(raw, value) {
		this.valuer.set(raw, value);
	},
	
	/**
	 * Creates deffered dao expression.
	 * Return value will enable to get & set the given path from the underlying storage.
	 */
	createDao: function(path) {
		return this.valuer.createDao(path);
	},
	
	/**
	 * Sets the configuration property with the value and priority on behalf of the given object.
	 * Will throw an exception if the priority slot is already marked with other object
	 * which will hold its override (method will try to resolve override conflict first).
	 * 
	 * @param String property
	 * @param Any value
	 * @param Object object - object modifying the property.
	 * @param Integer priority
	 */
	override: function(property, value, object, priority) {
		this.storage.override(property, value, object, priority);
	},
	
	/**
	 * Clears the configuration property corresponding to the given priority.
	 * Will silently ignore if the priority slot is marked with other object
	 * (would mean that the value was set on successful resolve of the override conflict).
	 * 
	 * @param String property
	 * @param Object object - object modifying the property.
	 * @param Integer priority
	 */
	clearOverride: function(property, object, priority) {
		this.storage.clearOverride(property, object, priority);
	},
	
	/**
	 * Registers listener under property corresponding to the given path.
	 * @param String path - given without any unnecessary leading dots (e.g path instead of .path).
	 * @param Function fn
	 */
	register: function(path, fn) {
		this.observable.register(path, fn);
	},
	
	/**
	 * Unregisters listener from property corresponding to the given path.
	 * @param String path - given without any unnecessary leading dots (e.g path instead of .path).
	 * @param Function fn
	 */
	unregister: function(path, fn) {
		this.observable.unregister(path, fn);
	}
};